const connection = require("../app/database");

class CommentService {
  // 创建评论
  async create(content, momentId, userId) {
    const statement =
      "insert into comment (content, moment_id, user_id) values (?, ?, ?);";

    try {
      const [result] = await connection.execute(statement, [
        content,
        momentId,
        userId,
      ]);
      return result;
    } catch (error) {
      console.log(error);
    }

    return result;
  }

  // 回复评论
  async reply(content, momentId, commentId, userId) {
    const statement = `insert into comment (content, moment_id, comment_id, user_id) values (?, ?, ?, ?);`;
    const [result] = await connection.execute(statement, [
      content,
      momentId,
      commentId,
      userId,
    ]);
    return result;
  }
}

module.exports = new CommentService();
